package view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import javax.swing.JDialog;
import javax.swing.JFrame;
import model.Base;
import model.Book;
import model.Document;
import view.DocumentResultView;

public class MainWindow extends JFrame {
	private static final long serialVersionUID = 1L;
	
	private Base model;
	private LoginView login;

	public MainWindow(Base model) {
		this.model = model;
		this.setLayout(new GridBagLayout());
		this.login = new LoginView(this.model, this);
		this.add(this.login);
		
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		
		this.setTitle("Projet LO43 bibliothècque");
		this.setMinimumSize(new Dimension(800, 600));
		this.setPreferredSize(new Dimension(800, 600));
		this.setVisible(true);
	}
	
	@Override
	public void dispose() {
		this.model.serialize();
		System.exit(0);
	}

	public void disconnect() {
		this.removeAll();
		this.add(this.login);
		this.validate();
	}
	
	public void accessGranted(int accesslevel) {
		this.remove(this.login);
		this.setLayout(new BorderLayout());
		if(accesslevel == 2) {
			this.add(new StaffMemberView(this.model, this));
		}
		else if(accesslevel == 1) {
			this.add(new UserView(this.model, this));
		}
		this.validate();

	}
	
}
